<?php 

namespace Home\Model;
use Think\Model;

class VercodeModel extends Model
{
	public function getOne(){
		$msg = M()->query('select * from vercode order by rand() limit 1');
		$question = current($msg)['question'];

		$_SESSION['answer']= current($msg)['answer'];
		return $question;
	}

	public function checkCode($answer)
	{
		if($answer==$_SESSION['answer']){
			return true;
		}else{
			return false;
		}
	}

	/*public function checkEmail($email){
		$emailsql = M()->query('select email from user where email="'.$email.'"');
		$reg='/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/';
		$res = preg_match($reg, $email);
		if($res){
			if($emailsql){
				return 3;
			}else{
				return 11;
			}
		}else{
			return 2;
		}
	}

	public function checkUser($username){
		$usersql = M()->query('select nickname from user where nickname="'.$username.'"');
		$reg='/^[a-zA-Z0-9_]{3,16}$/';
		$res=preg_match($reg, $username);
		if($res){
			if($usersql){
				return 6;
			}else{
				return 12;
			}
		}else{
			return 5;
		}
	}

	public function checkPass($pass){
		$reg='/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,18}$/';
		$res=preg_match($reg, $pass);
		if(!$res){
			return 7;
		}
	}*/
}

 ?>